﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using AspNetCs.IDAL;
using AspNetCs.Model;
using AspNetCs.SQLServerDAL;
using AspNetCs.DALFactory;
using AspNetCs.Common;

namespace AspNetCs.Bll
{
    public class MessageBLL
    {
        IMessage DAL = Conn.CreateMessage();

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(MessageModel model)
        {
            return DAL.Add(model);
        }

        /// <summary>
        /// 修改(修改用户查看消息状态)
        /// </summary>
        /// <param name="model">只需要提供Id,IsView,ViewTime的值</param>
        /// <returns></returns>
        public int Update(MessageModel model)
        {
            return DAL.Update(model);
        }


        /// <summary>
        /// 根据filter条件查询
        /// </summary>
        /// <param name="SearchPropertys">查询的字段(字段之间用逗号隔开,如果查询所有字段用*)</param>
        /// <param name="filter">筛选条件</param>
        /// <returns></returns>
        public DataTable GetDataTable(string SearchPropertys, string filter)
        {
            return DAL.GetDataTable(SearchPropertys,filter);
        }


        public MessageModel GetModel(DataRow row)
        {
            MessageModel model = new MessageModel();
            if(row!=null)
            {
                model.Content = row["Content"].ToString();
                model.Id =StringHelper.isNumber_int(row["id"].ToString());
                model.IsAll = StringHelper.isNumber_int(row["IsAll"].ToString());
                model.IsDel = StringHelper.isNumber_int(row["IsDel"].ToString());
                model.IsView = StringHelper.isNumber_int(row["IsView"].ToString());
                model.ReciverId = StringHelper.isNumber_int(row["ReciverId"].ToString());
                model.ReciverIsMaster = StringHelper.isNumber_int(row["ReciverIsMaster"].ToString());
                model.SenderId = StringHelper.isNumber_int(row["SenderId"].ToString());
                model.SenderIsMaster = StringHelper.isNumber_int(row["SenderIsMaster"].ToString());
                model.SendTime = StringHelper.isDatetime(row["SendTime"].ToString());
                model.Title = row["Title"].ToString();
                model.ViewTime = StringHelper.isDatetime(row["ViewTime"].ToString());
            }
            return model;
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public int Delete(string filter)
        {
            return DAL.Delete(filter);
        }
    }
}
